package org.example;


import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;

/**
 * @ClassName RandomConfig
 * @Description
 * @Author zhangsw
 * @Date 2021/1/13 20:57
 * @Version 1.0
 */
public class RandomConfig {

    public static Integer ljyStock = 5;
    public static Integer aqjmStock = 100;
    public static Integer ykwStock = 100;

    public static void main(String[] args) {
//        int count = 0;
//        for (int i = 0; i < 999999; i++) {
//            int rNumber = (int) (Math.random() * 1000 + 1);
//            System.out.println(rNumber);
//            if (rNumber > 1000 || rNumber < 1) {
//                count += 1;
//            }
//        }
//        System.err.println("count = " + count);


//        for (int i = 0; i < 100; i++) {
//            System.out.println(getCard());
//        }
        for (int i = 0; i < 210; i++) {
            System.err.println(getPrize(0));
        }

//        Integer a= 10000000000;

    }

    private static String getCard() {
        Integer randomNumber = randomNumber();
        if (randomNumber<=10) { //1%的概率
            return "千";
        } else if (randomNumber <= 200) { //19%的概率
            return "兆";
        } else if (randomNumber <= 300) { //10%的概率
            return "用";
        } else if (randomNumber <= 500) { //20%的概率
            return "电";
        } else { //50%的概率
            return "信";
        }
    }

    private static String getPrize(int count) {
        if (count > 3) {
            return "无库存";
        }
        //生成随机数
        Integer randomNumber = randomNumber();
        if (randomNumber<=10) { //1%的概率
            if (ljyStock <= 0) {
                return getPrize(++count);
            }
            ljyStock--;
            return "优酷视频会员年卡";
        } else if (randomNumber <= 200) { //19%的概率
            if (aqjmStock <= 0) {
                return getPrize(++count);
            }
            aqjmStock--;
            return "爱奇艺会员月卡";
        } else { //80%的概率
            if (ykwStock <= 0) {
                return getPrize(++count);
            }
            ykwStock--;
            return "优酷视频会员周卡";
        }
    }

    private static Integer randomNumber() {
        return (int) (Math.random() * 1000 + 1);
    }

}
